package com.quanyue.haircut.shop.service.impl;

import com.quanyue.auto.util.AssertUtils;
import com.quanyue.haircut.domain.entity.ShopServer;
import com.quanyue.haircut.shop.mapper.ShopServerMapper;
import com.quanyue.haircut.shop.service.ShopServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ShopServerServiceImpl implements ShopServerService {
    @Autowired
    private ShopServerMapper shopServerMapper;

    @Override
    public void createShopServer(List <ShopServer> shopServers) {
        shopServers.forEach(shopServer -> {
            shopServer.setCreateTime(LocalDateTime.now());
            shopServer.setModifyTime(LocalDateTime.now());
            shopServer.setDelFlag(false);
        });
        shopServerMapper.insertAll(shopServers);
    }

    @Override
    public void updateShopServer(ShopServer shopServer) {
        ShopServer check = shopServerMapper.findOne(shopServer.getId());
        AssertUtils.notNull(check, "店铺服务信息校检出错");
        shopServer.setCreateTime(check.getCreateTime());
        shopServer.setModifyTime(LocalDateTime.now());
        shopServer.setDelFlag(false);
        shopServerMapper.update(shopServer);
    }

    @Override
    public void deleteShopServer(Integer shopServerId) {
        shopServerMapper.deleteOne(shopServerId);
    }

    @Override
    public List <ShopServer> shopServerList(Integer shopId) {
        return shopServerMapper.findByShop(shopId);
    }
}
